<?php

if (!function_exists('paging')) {

    //Ham xoa comment trong cac file php, html, js, css.
    function paging($page_size, $page, $total_rows) {
        if ($page_size <= 0)
            $page_size = 1;
        if ($page <= 0)
            $page = 1;
        $total_pages = ceil($total_rows / $page_size);
        $paging = new stdClass();
        $paging->page_size = $page_size;
        $paging->current_page = $page;
        $paging->total_pages = $total_pages;
        $paging->has_previous = $page > 1;
        $paging->previous_page = max(1, $page - 1);
        $paging->has_next = $page < $total_pages;
        $paging->next_page = min($total_pages, $page + 1);
        return $paging;
    }

}